﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;

public partial class Main_Accounts_TDSOption : System.Web.UI.Page
{
    Datautility DU = new Datautility();
    string strsql = string.Empty;
    int intControlCounter = 0;
    List<string> LstRowCount;
    List<string> LstLedgerName;
    List<string> LstLedgerId;
    List<string> LstRateType;
    List<string> LstIsTdsFirstBill;

    //protected override void LoadViewState(object savedState)
    //{
    //    base.LoadViewState(savedState);

    //    LstRowCount = (List<string>)ViewState["LstRowCount"];
    //    LstLedgerName = (List<string>)ViewState["LstRowCount"];
    //    LstLedgerId = (List<string>)ViewState["LstRowCount"];
    //    LstRateType = (List<string>)ViewState["LstRowCount"];
    //    LstIsTdsFirstBill = (List<string>)ViewState["LstRowCount"];

    //    if (LstRowCount != null)
    //    {
    //        int rowCount = Convert.ToInt32(LstRowCount.Count);
    //        for (int i = 0; i < rowCount; i++)
    //        {
    //            intControlCounter++;
    //            HtmlTableRow HTRow = new HtmlTableRow();

    //            HtmlTableCell HTCell1 = new HtmlTableCell();

    //            Label lblLedgerName = new Label();
    //            lblLedgerName.ID = LstLedgerName[i].ToString();
    //            lblLedgerName.Width = Unit.Percentage(98);
    //            HiddenField hidLedgerId = new HiddenField();
    //            hidLedgerId.ID = LstLedgerId[i].ToString();
    //            HTCell1.Controls.Add(lblLedgerName);
    //            HTCell1.Controls.Add(hidLedgerId);

    //            HtmlTableCell HTCell2 = new HtmlTableCell();

    //            DropDownList ddlRateType = new DropDownList();
    //            ddlRateType.ID = LstRateType[i].ToString();
    //            ddlRateType.Items.Add(new ListItem("TDS", "1"));
    //            ddlRateType.Items.Add(new ListItem("NonTDS", "2"));
    //            ddlRateType.Items.Add(new ListItem("LowerTDS", "3"));
    //            ddlRateType.CssClass = "dropdown";
    //            ddlRateType.Width = Unit.Percentage(98);
    //            HTCell2.Controls.Add(ddlRateType);

    //            HtmlTableCell HTCell3 = new HtmlTableCell();
    //            CheckBox chkTdsFromFirstBill = new CheckBox();
    //            chkTdsFromFirstBill.ID = LstIsTdsFirstBill[i].ToString();
    //            HTCell3.Controls.Add(chkTdsFromFirstBill);

    //            HTRow.Cells.Add(HTCell1);
    //            HTRow.Cells.Add(HTCell2);
    //            HTRow.Cells.Add(HTCell3);
    //            tblTDSOption.Rows.Add(HTRow);
    //        }
    //    }
    //}

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            LstRowCount = new List<string>();
            ViewState["LstRowCount"] = LstRowCount;
            
            LstLedgerName = new List<string>();
            ViewState["LstLedgerName"] = LstLedgerName;

            LstLedgerId = new List<string>();
            ViewState["LstLedgerId"] = LstLedgerId;

            LstRateType = new List<string>();
            ViewState["LstRateType"] = LstRateType;

            LstIsTdsFirstBill = new List<string>();
            ViewState["LstIsTdsFirstBill"] = LstIsTdsFirstBill;            
        }
        _BindTdsOptionLedger();
    }
    private void _AddMoreRow()
    {
        intControlCounter++;
        HtmlTableRow HTRow = new HtmlTableRow();

        HtmlTableCell HTCell1 = new HtmlTableCell();

        Label lblLedgerName = new Label();
        lblLedgerName.ID = "lblLedgerName" + intControlCounter.ToString();
        lblLedgerName.Width = Unit.Percentage(98);
        HiddenField hidLedgerId = new HiddenField();
        hidLedgerId.ID = "hidLedgerId" + intControlCounter.ToString();
        HTCell1.Controls.Add(lblLedgerName);
        HTCell1.Controls.Add(hidLedgerId);
        //LstRowCount.Add(intControlCounter.ToString());
        //LstLedgerName.Add(lblLedgerName.ID);
        //LstLedgerId.Add(hidLedgerId.ID);


        HtmlTableCell HTCell2 = new HtmlTableCell();

        DropDownList ddlRateType = new DropDownList();
        ddlRateType.ID = "ddlRateType" + intControlCounter.ToString();
        ddlRateType.Items.Add(new ListItem("TDS", "1"));
        ddlRateType.Items.Add(new ListItem("NonTDS", "2"));
        ddlRateType.Items.Add(new ListItem("LowerTDS", "3"));
        ddlRateType.CssClass = "dropdown";
        ddlRateType.Width = Unit.Percentage(98);
        HTCell2.Controls.Add(ddlRateType);
        //LstRateType.Add(ddlRateType.ID);

        HtmlTableCell HTCell3 = new HtmlTableCell();
        CheckBox chkTdsFromFirstBill=new CheckBox();
        chkTdsFromFirstBill.ID = "chkTdsFromFirstBill" + intControlCounter.ToString();
        HTCell3.Controls.Add(chkTdsFromFirstBill);
        //LstIsTdsFirstBill.Add(chkTdsFromFirstBill.ID);

        HTRow.Cells.Add(HTCell1);
        HTRow.Cells.Add(HTCell2);
        HTRow.Cells.Add(HTCell3);
        tblTDSOption.Rows.Add(HTRow);
        
        //ViewState["LstRowCount"] = LstRowCount;
        //ViewState["LstLedgerName"] = LstLedgerName;
        //ViewState["LstLedgerId"] = LstLedgerId;
        //ViewState["LstRateType"] = LstRateType;
        //ViewState["LstIsTdsFirstBill"] = LstIsTdsFirstBill;
        hidTblRowCount.Value = intControlCounter.ToString();        
    }
    private void _BindTdsOptionLedger()
    {
        strsql = "Select LID,LNAME from ACC_LEDMAST where TDSAPPLY=1";
        DataTable DT = DU.getdata(strsql);
        if (DT.Rows.Count > 0)
        {
            for (int i = 1; i <= DT.Rows.Count; i++)
            {
                _AddMoreRow();
            }
            for (int i = 1; i <= DT.Rows.Count; i++)
            {
                Label lblLedgerName = (Label)tblTDSOption.Rows[i].FindControl("lblLedgerName" + i);
                HiddenField hidLedgerId = (HiddenField)tblTDSOption.Rows[i].FindControl("hidLedgerId" + i);
                DropDownList ddlRateType = (DropDownList)tblTDSOption.Rows[i].FindControl("ddlRateType" + i);
                CheckBox chkTdsFromFirstBill = (CheckBox)tblTDSOption.Rows[i].FindControl("chkTdsFromFirstBill" + i);
                lblLedgerName.Text = DT.Rows[i - 1]["LNAME"].ToString();
                hidLedgerId.Value = DT.Rows[i - 1]["LID"].ToString();
            }
        }
    }

}
